package tool

// by daoyi
//本人封装的websocket方法
import (
	"context"
	"fmt"
)

const (
	PublishKey = "websocket"
)

// Publish 发布消息到Redis
func Publish(infotx context.Context, channel string, msg string) error {
	var err error
	//infotx页面请求的东西，channel管道，msg消息
	fmt.Println("Publish ...", msg)
	err = Red.Publish(infotx, channel, msg).Err()
	return err
}

// Subscribe 订阅Redis消息
func Subscribe(infotx context.Context, channel string) (string, error) {
	sub := Red.Subscribe(infotx, channel)
	//fmt.Println("Subscribe ...", sub)
	msg, err := sub.ReceiveMessage(infotx)
	//打印订阅消息
	fmt.Println("Subscribe ...", sub)
	return msg.Payload, err
}
